package com.shigu.mo.services;

import com.opentae.data.mall.beans.MoOverallSituation;
import com.opentae.data.mall.examples.MoOverallSituationExample;
import com.opentae.data.mall.interfaces.MoOverallSituationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 全局服务
 */
@Service
public class OverallSituationService {
    private Boolean openProgram=true;//开启或关闭程序

    @Autowired
    private MoOverallSituationMapper moOverallSituationMapper;

    public void reload(){
        MoOverallSituationExample example=new MoOverallSituationExample();
        example.setStartIndex(0);
        example.setEndIndex(1);
        List<MoOverallSituation> situations=moOverallSituationMapper.selectByConditionList(example);
        if (situations.size()>0) {
            MoOverallSituation situation=situations.get(0);
            openProgram=situation.getOpenProgram();
        }
    }

    /**
     * 查询系统公告
     * @return
     */
    @Cacheable("systemmsg_cach")
    public String selSystemMsg(){
        MoOverallSituationExample example=new MoOverallSituationExample();
        example.setStartIndex(0);
        example.setEndIndex(1);
        List<MoOverallSituation> situations=moOverallSituationMapper.selectByConditionList(example);
        if (situations.size()>0) {
            MoOverallSituation situation=situations.get(0);
            return situation.getSystemMsg();
        }
        return "";
    }

    public Boolean getOpenProgram() {
        return openProgram;
    }

    public void setOpenProgram(Boolean openProgram) {
        this.openProgram = openProgram;
    }
}
